﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ImageDemo.PictureBoxDemo
{
    public partial class PictureMoveByCommand : Form
    {
        public PictureMoveByCommand()
        {
            InitializeComponent();
        }

        private void btnUp_Click(object sender, EventArgs e)
        {
            if (pbMove.Location.Y > plContainer.Location.Y + 5)
            {
                pbMove.Location = new Point(pbMove.Location.X, pbMove.Location.Y - 5);
                pbMove.Refresh();
            }
            
        }

        private void btnLeft_Click(object sender, EventArgs e)
        {
            if (pbMove.Location.X > plContainer.Location.X + 5)
            {
                pbMove.Location = new Point(pbMove.Location.X - 5, pbMove.Location.Y);
                pbMove.Refresh();
            }
        }

        private void btnDown_Click(object sender, EventArgs e)
        {
            if (pbMove.Location.Y + pbMove.Width + 5 < plContainer.Location.Y + plContainer.Height)
            {
                pbMove.Location = new Point(pbMove.Location.X, pbMove.Location.Y + 5);
                pbMove.Refresh();
            }
        }

        private void btnRight_Click(object sender, EventArgs e)
        {
            if (pbMove.Location.X + pbMove.Height + 5 < plContainer.Location.X + plContainer.Width)
            {
                pbMove.Location = new Point(pbMove.Location.X + 5, pbMove.Location.Y);
                pbMove.Refresh();
            }
        }

        private void PictureMoveByCommand_Load(object sender, EventArgs e)
        {
            pbMove.SizeMode = PictureBoxSizeMode.AutoSize;
            string strBasePath = AppDomain.CurrentDomain.BaseDirectory;
            string strTemp = strBasePath.Substring(0, strBasePath.IndexOf(@"demo\"));
            string imgPath = strTemp + @"demo\data\head.jpg";
            pbMove.ImageLocation = imgPath;
            pbMove.Load();
        }
    }
}
